package com.lovo.roomProject.updatePwd.service.impl;

import com.lovo.roomProject.pojo.LoginUser;
import com.lovo.roomProject.pojo.SystemDO;
import com.lovo.roomProject.updatePwd.dao.UpdatePwdDAO;
import com.lovo.roomProject.updatePwd.dao.impl.UpdatePwdDAOImpl;
import com.lovo.roomProject.updatePwd.service.UpdatePwdService;

public class UpdatePwdServiceImpl implements UpdatePwdService {
    private  UpdatePwdDAO updatePwdDAO=new UpdatePwdDAOImpl();
    @Override
    public void update(LoginUser systemDO,LoginUser newloginuser,LoginUser newLoginUser) throws Exception{
        LoginUser lodLoginUser=updatePwdDAO.getUserName(systemDO.getLoginUserName());
        if (!lodLoginUser.getLoginUserPwd().equals(systemDO.getLoginUserPwd())){
            throw new Exception("原密码错误");
        }
        if (lodLoginUser.getLoginUserPwd().equals(newloginuser.getLoginUserPwd())){
            throw new Exception("新密码不能与原密码相同");
        }
        if (!newloginuser.getLoginUserPwd().equals(newLoginUser.getLoginUserPwd())){
            throw new Exception("两次密码不一致");
        }
        lodLoginUser.setLoginUserPwd(newLoginUser.getLoginUserPwd());
        updatePwdDAO.update(lodLoginUser);
    }

    @Override
    public LoginUser getUserName(String name) {
        return updatePwdDAO.getUserName(name);
    }
}
